home *** CD-ROM | disk | FTP | other *** search
/ Risc World 3 / Risc World 3.iso / SOFTWARE / ISSUE6 / PD / PDF / DrawFile / c++ / GuiDrawFileText < prev   
Text File  |  2003-02-14  |  4KB  |  99 lines

  1. //--------------------------------------------------------------------------
  2. //
  3. //   Copyright (c) 2002, Colin Granville
  4. //
  5. //   All rights reserved.
  6. //
  7. //   Redistribution and use in source and binary forms, with or
  8. //   without modification, are permitted provided that the following 
  9. //   conditions are met:
  10. //
  11. //      * Redistributions of source code must retain the above copyright 
  12. //        notice, this list of conditions and the following disclaimer.
  13. //
  14. //      * Redistributions in binary form must reproduce the above 
  15. //        copyright notice, this list of conditions and the following 
  16. //        disclaimer in the documentation and/or other materials 
  17. //        provided with the distribution.
  18. //
  19. //      * The name Colin Granville may not be used to endorse or promote 
  20. //        products derived from this software without specific prior 
  21. //        written permission.
  22. //
  23. //   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
  24. //   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
  25. //   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
  26. //   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
  27. //   COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
  28. //   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
  29. //   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
  30. //   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
  31. //   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
  32. //   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
  33. //   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
  34. //   OF THE POSSIBILITY OF SUCH DAMAGE.
  35. //
  36. //--------------------------------------------------------------------------
  37.  
  38. #include "GuiDrawFileText.h"
  39. #include "iostream.h"
  40. #include <limits.h>
  41.  
  42. GuiDrawFileText::GuiDrawFileText(GuiDrawFile& d)
  43.  : drawfile(d)
  44. {
  45.   ob.typeId=OBJECT_ID;
  46. }
  47.  
  48. //***************************************************************
  49.  
  50. GuiDrawFileText::~GuiDrawFileText()
  51. {
  52. }
  53.  
  54. //***************************************************************
  55.  
  56. void GuiDrawFileText::start()
  57. {
  58.   ob.size=drawfile.startObject(sizeof(GuiDrawFileGraphicsObject) + sizeof(GuiDrawFileTextState));
  59. }
  60.  
  61. //***************************************************************
  62.  
  63. void GuiDrawFileText::end(const GuiDrawFileTextState& state, int handle)
  64. {
  65.   static struct {int a[5];GuiBBox bounds;} fscb = {0,0, 0,0, -1, {0,0,0,0}};
  66.   put('\0');
  67.  
  68.   int i;
  69.   for (i=drawfile.getSize();i & 3;i++) put('\0');
  70.  
  71.   if (drawfile.hasFailed()) return;
  72.  
  73.  
  74.   _swix(Font_ScanString,_INR(0,6), handle,
  75.                                    drawfile.getPtr(ob.size+sizeof(GuiDrawFileGraphicsObject) +
  76.                                                            sizeof(GuiDrawFileTextState)),
  77.                                    (1<<5) | (1<<6)  | (1<<8) | (1<<18),
  78.                                    INT_MIN,INT_MIN,&fscb,&state.transform);
  79.  
  80.   //should be 16/25 but 21/32 is faster and it needs a bit extra anyway
  81.   ob.bounds.xmin=fscb.bounds.xmin*21/32+state.x-4*256;
  82.   ob.bounds.xmax=fscb.bounds.xmax*21/32+state.x;
  83.   ob.bounds.ymin=fscb.bounds.ymin*21/32+state.y-4*256;
  84.   ob.bounds.ymax=fscb.bounds.ymax*21/32+state.y;
  85.   int offset=ob.size;
  86.   ob.size=i-offset;
  87.   *(GuiDrawFileGraphicsObject*)drawfile.getPtr(offset)=ob;
  88.   *(GuiDrawFileTextState*)drawfile.getPtr(offset+sizeof(GuiDrawFileGraphicsObject))=state;
  89.   drawfile.addBBox(ob.bounds);
  90.   drawfile.endObject();
  91. }
  92.  
  93. //***************************************************************
  94.  
  95. void GuiDrawFileText::put(const char* s)
  96. {
  97.   for (;*s;s++) put(*s);
  98. }
  99.